package com.example.todolist.util;

import cn.hutool.http.HttpUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * @author: yoonada
 * @email: m15602498163@163.com
 * @create: 2021-12-06 20:27
 * @description: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html
 */
@Slf4j
public class WeChatUtil {

    public static final String PARAMS_TEMPLATE = "appid=%s&secret=%s&js_code=%s&grant_type=authorization_code";

    public static String code2Session(WeChatCode2SessionReq dto) {
        String paramsUrl = String.format(PARAMS_TEMPLATE, dto.getAppKey(), dto.getSecret(), dto.getCode());
        String url = String.join("?", dto.getRequestUrl(), paramsUrl);
        return HttpUtil.get(url);
    }

}